home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-02-21 | 24.5 KB | 1,085 lines | [TEXT/MPCC] |
- //
- // File: MacFramework.c
- //
- // Contains: Basic functions for windows, menus, and similar things.
- //
- // Written by: Tim Monroe
- // Based (heavily!) on the MovieShell code written by Apple DTS
- //
- // Copyright: © 1994-1996 by Apple Computer, Inc., all rights reserved.
- //
- // Change History (most recent first):
- //
- // <9> 01/06/97 rtm DoIdle now called for all open app windows
- // <8> 01/02/97 rtm added gAppInForeground flag
- // <7> 12/17/96 rtm fixed crashing bug in DoCreateMovieWindow
- // (hitting Cancel in open dialog left wrong port setting)
- // <6> 12/17/96 rtm added GetAppDataFromFrontWindow, GetAppDataFromWindow, GetAppDataFromWindowObject
- // <5> 12/09/96 rtm added RemoveApplicationWindowObject hook to allow app-specific clean-up
- // <4> 12/04/96 rtm added support for HL events
- // <3> 12/02/96 rtm added CheckMovieControllers function
- // <2> 11/27/96 rtm conversion to personal coding style
- // <1> 12/20/94 khs first file
- //
- //
-
- // header files
- #include <SegLoad.h>
- #include <ToolUtils.h>
- #include <Devices.h>
- #include <Fonts.h>
-
- #include "DTSQTUtilities.h"
- #include "AppConfiguration.h"
- #include "MacFramework.h"
-
-
- // window definitions
- Rect gDefaultWinRect;
- Rect gLimitRect = {0, 0, 480, 640}; // max size for any window
- long gMCFlags = kMCFlags;
-
- // global variables
- Boolean gQuitFlag = false; // flag that keeps track of termination state
- unsigned long gWNEsleep = kWNEDefaultSleep; // WaitNextEvent sleep time
- Str255 gWindowTitle = "\pUntitled"; // default name for created windows
- GrowZoneUPP gAppGrowZoneUPP; // our grow zone callback
- Boolean gAppInForeground; // is our application in the foreground?
-
- // pure Macintosh Toolbox functions
-
- //////////
- //
- // InitMacEnvironment
- // Initialize the Macintosh runtime environment.
- //
- //////////
-
- void InitMacEnvironment (long theNumMasters)
- {
- long myIndex;
-
- // expand heap zone to its limit
- MaxApplZone();
-
- for (myIndex = 0; myIndex < theNumMasters; myIndex++) {
- MoreMasters();
- }
-
- InitGraf(&qd.thePort);
- InitFonts();
- FlushEvents(everyEvent, 0);
- InitWindows();
- InitMenus();
- TEInit();
- InitCursor();
- InitDialogs(NULL);
-
- // install a growzone proc warning about low memory situation
- gAppGrowZoneUPP = NewGrowZoneProc(AppGrowZoneCallback);
- SetGrowZone(gAppGrowZoneUPP);
-
- // initialize foreground/background state
- gAppInForeground = true;
-
- // do any application-specific initialization
- InitApplication();
- }
-
-
- //////////
- //
- // InitStack
- // Add some extra space to the stack.
- //
- //////////
-
- void InitStack (long theExtraStackSpace)
- {
- Ptr mySize;
-
- mySize = GetApplLimit();
- SetApplLimit(mySize - theExtraStackSpace);
- }
-
-
- //////////
- //
- // AppGrowZoneCallback
- // Our grow zone procedure.
- //
- //////////
-
- pascal void AppGrowZoneCallback (void)
- {
- long myA5;
- Size myTempSize;
- Size myAvailMem;
-
- myA5 = SetCurrentA5();
-
- myAvailMem = MaxMem(&myTempSize);
-
- if (myAvailMem < kAvailableMem) {
- ShowWarning("\pWe are running out of memory, increase the application heap! Exiting the application.", 0);
- ExitToShell();
- }
-
- SetA5(myA5);
- }
-
-
- //////////
- //
- // InitMenubar
- // Set up the menu bar.
- //
- //////////
-
- Boolean InitMenubar (void)
- {
- Handle myMenuHandle = NULL;
-
- myMenuHandle = GetNewMBar(mMenubar); DebugAssert(myMenuHandle != NULL);
- if (myMenuHandle == NULL) {
- ShowWarning("\pCould not find the Menubar resource!", 0);
- return(false);
- }
-
- SetMenuBar(myMenuHandle);
- DisposeHandle(myMenuHandle); DebugAssert(MemError() == noErr);
-
- AddResMenu(GetMHandle(mApple), 'DRVR');
-
- DrawMenuBar();
-
- return(true);
- }
-
-
- //////////
- //
- // HandleMenuCommand
- // Handle a menu selection.
- //
- //////////
-
- void HandleMenuCommand (long theMenuResult)
- {
- short myMenuID, myMenuItem;
- Str255 myDAName;
-
- SetCursor(&qd.arrow);
-
- myMenuID = HiWord(theMenuResult);
- myMenuItem = LoWord(theMenuResult);
-
- switch (myMenuID) {
-
- case mApple:
- switch (myMenuItem) {
- case iAbout: // about box
- ShowAboutDialogBox();
- break;
-
- default: // Apple menu handling
- GetItem(GetMHandle(mApple), myMenuItem, myDAName);
- (void)OpenDeskAcc(myDAName);
- break;
- }
- break;
-
- case mFile:
- switch (myMenuItem) {
- case iNew:
- if (!DoCreateNewMovie()) {
- SysBeep(kDefaultSysBeep);
- ShowWarning("\pCould not create a new movie!", 0);
- break;
- }
- break;
-
- case iOpen:
- if (!DoCreateMovieWindow(NULL)) {
- ShowWarning("\pCould not create a new movie window!", 0);
- SysBeep(kDefaultSysBeep);
- break;
- }
- break;
-
- case iClose:
- DoDestroyMovieWindow(FrontWindow());
- break;
-
- case iSave:
- if (!DoUpdateMovieFile(FrontWindow())) {
- SysBeep(kDefaultSysBeep);
- ShowWarning("\pCould not save the movie file!", 0);
- break;
- }
- break;
-
- case iSaveAs: {
- MovieController myMC;
-
- myMC = GetMCFromFrontWindow();
- if (myMC == NULL) {
- SysBeep(kDefaultSysBeep);
- break;
- }
-
- if (QTUSaveMovie(MCGetMovie(myMC)) != noErr) {
- SysBeep(kDefaultSysBeep);
- ShowWarning("\pCould not save the movie file!", 0);
- break;
- }
-
- break;
- }
-
- case iPrint: {
- MovieController myMC;
- OSErr myErr = noErr;
-
- myMC = GetMCFromFrontWindow();
- if (myMC != NULL) {
- myErr = QTUPrintMoviePICT(MCGetMovie(myMC), kDefaultX, kDefaultY, kPrintFrame);
- if (myErr != noErr) {
- ShowWarning("\pCould not print!", myErr);
- SysBeep(kDefaultSysBeep);
- }
- } else
- SysBeep(kDefaultSysBeep);
- break;
- }
-
- case iQuit:
- gQuitFlag = true;
-
- // do any application-specific shutdown
- StopApplication();
- break;
-
- }
- break;
-
-
- // Provide the default controller cut, copy and paste functionality.
- case mEdit: {
- Movie myMovie = NULL;
- MovieController myMC;
-
- myMC = GetMCFromFrontWindow();
- if (myMC == NULL)
- break;
-
- switch (myMenuItem) {
- case iUndo:
- MCUndo(myMC);
- break;
-
- case iCut:
- myMovie = MCCut(myMC);
- break;
-
- case iCopy:
- myMovie = MCCopy(myMC);
- break;
-
- case iPaste:
- MCPaste(myMC, NULL);
- break;
-
- case iClear:
- MCClear(myMC);
- break;
-
- case iSelectAll:
- if (QTUSelectAllMovie(myMC) != noErr)
- SysBeep(kDefaultSysBeep);
- break;
- }
-
- if (myMovie) {
- PutMovieOnScrap(myMovie, 0);
- DisposeMovie(myMovie); DebugAssert(MemError() == noErr);
- }
-
- break;
- }
-
-
- default:
- HandleApplicationMenu(myMenuID, myMenuItem);
- break;
- }
-
- HiliteMenu(0);
- }
-
-
- //////////
- //
- // AdjustMenus
- // Adjust the application's menus.
- //
- //////////
-
- void AdjustMenus (void)
- {
- WindowRef myWindow;
- MovieController myMC;
- WindowObject myWindowObject;
-
- myWindow = FrontWindow();
-
- if (myWindow != NULL) {
- EnableItem(GetMHandle(mFile), iClose);
-
- if ((myWindowObject = (WindowObject)GetWRefCon(myWindow)) != NULL) {
-
- myMC = (**myWindowObject).fController;
- if ((IsWindowObjectOurs(myWindowObject)) && (myMC != NULL)) {
- MCSetUpEditMenu(myMC, 0L, GetMHandle(mEdit));
- EnableItem(GetMHandle(mEdit), iSelectAll);
- EnableItem(GetMHandle(mFile), iSave);
- EnableItem(GetMHandle(mFile), iSaveAs);
- EnableItem(GetMHandle(mFile), iClose);
- EnableItem(GetMHandle(mFile), iPrint);
- }
- }
- } else {
- DisableItem(GetMHandle(mFile), iSave);
- DisableItem(GetMHandle(mFile), iSaveAs);
- DisableItem(GetMHandle(mFile), iClose);
- DisableItem(GetMHandle(mFile), iPrint);
-
- DisableItem(GetMHandle(mEdit), iCut);
- DisableItem(GetMHandle(mEdit), iCopy);
- DisableItem(GetMHandle(mEdit), iPaste);
- DisableItem(GetMHandle(mEdit), iUndo);
- DisableItem(GetMHandle(mEdit), iClear);
- DisableItem(GetMHandle(mEdit), iSelectAll);
-
- }
-
- AdjustApplicationMenus(); // fix any app-specific menus as well
- }
-
-
- //////////
- //
- // CheckMovieControllers
- // Let all movie controllers have a chance to process the event.
- //
- //////////
-
- Boolean CheckMovieControllers (EventRecord *theEvent)
- {
- WindowPtr myWindow;
- Boolean isMovieEvent = false;
- WindowObject myWindowObject;
- MovieController myMC;
-
- myWindow = FrontWindow();
- while (myWindow) {
- myWindowObject = (WindowObject)GetWRefCon(myWindow);
- if (myWindowObject) {
- if (IsWindowObjectOurs(myWindowObject)) {
- myMC = (**myWindowObject).fController;
- if (myMC) {
- if (MCIsPlayerEvent(myMC, theEvent)) {
- isMovieEvent = true;
- }
- }
- }
- }
- myWindow = (WindowPtr)(((WindowRecord*)myWindow)->nextWindow);
- }
-
- return(isMovieEvent);
- }
-
-
- //////////
- //
- // MainEventLoop
- // Retrieve and process events.
- //
- //////////
-
- void MainEventLoop (void)
- {
- EventRecord myEvent;
- WindowRef myWindow;
- Boolean isMovieEvent;
- short myWindowPart;
- Rect myScreenRect;
- Rect myRefreshArea;
- Point myPoint = {100, 100};
-
- while (!gQuitFlag) {
- WaitNextEvent(everyEvent, &myEvent, gWNEsleep, NULL);
-
- #ifdef USESIOUX
- SIOUXHandleOneEvent(&myEvent);
- #endif USESIOUX
-
- AdjustMenus();
-
- // first, let all active movie controllers have access to the event
- isMovieEvent = CheckMovieControllers(&myEvent);
-
- // then, if this wasn't a movie controller event, pass it on to the case statement
- // that dispatches the event to the right function.
- if (!isMovieEvent) {
-
- myWindow = FrontWindow();
-
- switch (myEvent.what) {
- case mouseDown:
-
- myWindowPart = FindWindow(myEvent.where, &myWindow);
-
- // window-related events:
- switch (myWindowPart) {
- case inMenuBar:
- HandleMenuCommand(MenuSelect(myEvent.where));
- break;
-
- case inDrag: {
- Rect myRect;
- Movie myMovie = NULL;
- MovieController myMC = NULL;
- WindowObject myWindowObject = NULL;
-
- myWindowObject = (WindowObject)GetWRefCon(myWindow);
- myMC = (**myWindowObject).fController;
- if (!(IsWindowObjectOurs(myWindowObject)) && (myMC == NULL))
- break;
-
- myMovie = MCGetMovie(myMC);
-
- GetMovieBox(myMovie, &myRect);
- myScreenRect = (**GetGrayRgn()).rgnBBox;
- DragAlignedWindow(myWindow, myEvent.where, &myScreenRect, &myRect, NULL);
- }
- break;
-
- case inContent:
- SelectWindow(myWindow);
- HandleContentClick(myWindow, &myEvent);
- break;
-
- case inGoAway:
- // if the window is closed, dispose the movie, the controller and the window
- if (TrackGoAway(myWindow, myEvent.where))
- DoDestroyMovieWindow(myWindow);
- break;
- } // end switch(myWindowPart)
- break;
-
- // system-level events:
- case updateEvt:
- myWindow = (WindowRef)myEvent.message;
- myRefreshArea = ((**(myWindow->visRgn)).rgnBBox);
- DoUpdateWindow(myWindow, &myRefreshArea);
- break;
-
- case keyDown:
- case autoKey:
- HandleKeyPress(&myEvent);
- break;
-
- case diskEvt:
- if (HiWord(myEvent.message) != noErr)
- (void)DIBadMount(myPoint, myEvent.message);
- break;
-
- case activateEvt:
- myWindow = (WindowRef)myEvent.message;
-
- if (IsAppWindow(myWindow)) {
- DoActivateWindow(myWindow, ((myEvent.modifiers & activeFlag) != 0 ));
- }
- break;
-
- case osEvt:
- switch ((myEvent.message > 24) & 0x00FF) { // get high byte of word
- case suspendResumeMessage:
-
- // set the foreground/background state
- if ((myEvent.message & resumeFlag) != 0)
- gAppInForeground = true;
- else
- gAppInForeground = false;
-
- // activate the front window, if there is one
- if (FrontWindow()) {
- DoActivateWindow(FrontWindow(), !((myEvent.message & resumeFlag) == 0));
- }
- break;
-
- case mouseMovedMessage:
- break;
- }
- break;
-
- case kHighLevelEvent:
- AEProcessAppleEvent(&myEvent);
- break;
-
- case nullEvent:
- // do idle-time processing for all open windows in our window list
- myWindow = FrontWindow();
- while (myWindow != NULL) {
- if (gAppInForeground)
- DoIdle(myWindow);
- myWindow = (WindowPtr)(((WindowRecord*)myWindow)->nextWindow);
- }
- break;
-
- } //switch (myEvent.what)
- } //if (!isMovieEvent)
- } //while (!gQuitFlag)
- }
-
-
- //////////
- //
- // IsAppWindow
- // Does the specified window belong to our application?
- //
- //////////
-
- Boolean IsAppWindow (WindowRef theWindow)
- {
- short myWindowKind;
-
- if (theWindow == NULL)
- return(false);
- else {
- myWindowKind = ((WindowPeek)theWindow)->windowKind;
- return((myWindowKind >= userKind) || (myWindowKind == dialogKind));
- }
- }
-
-
- //////////
- //
- // CreateWindowObject
- // Create a window object for the specified window.
- //
- //////////
-
- WindowObject CreateWindowObject (WindowRef theWindow)
- {
- WindowObject myWindowObject = NULL;
-
- myWindowObject = (WindowObject)NewHandleClear(sizeof(WindowObjectRecord));
-
- if (myWindowObject != NULL) {
- (**myWindowObject).fWindow = theWindow;
- (**myWindowObject).fController = NULL;
- (**myWindowObject).fObjectType = kMovieControllerObject;
- (**myWindowObject).fAppData = NULL;
- SetWRefCon(theWindow, (long)myWindowObject); // store a ref to the record in the window
- }
-
- return(myWindowObject);
- }
-
-
- //////////
- //
- // HandleKeyPress
- // Handle key presses.
- //
- //////////
-
- void HandleKeyPress (EventRecord *theEvent)
- {
- char myKey;
-
- myKey = theEvent->message & charCodeMask;
-
- if (theEvent->modifiers & cmdKey) {
- // if the command key is down, it must be a keyboard shortcut for a menu selection
- HandleMenuCommand(MenuKey(myKey));
- } else {
- // otherwise, we'll assume it's meant for our application
- HandleQTVRKeyPress(theEvent);
- }
- }
-
-
- //////////
- //
- // ShowAboutDialogBox
- // Display the About box.
- //
- //////////
-
- void ShowAboutDialogBox (void)
- {
- DialogPtr myDialog;
- short myItem;
- //FontInfo myFontInfo;
- GrafPtr mySavedPort;
-
- GetPort(&mySavedPort);
- myDialog = GetNewDialog(kAboutBox, NULL, (WindowPtr) -1L); DebugAssert(myDialog != NULL);
- SetPort(myDialog);
-
- // change font to Geneva, 9pt, bold, just for the sake of it...
- //TextFont(applFont); TextSize(9); TextFace(bold);
- //GetFontInfo(&myFontInfo);
-
- //(*((DialogPeek)myDialog)->textH)->txFont = applFont;
- //(*((DialogPeek)myDialog)->textH)->txSize = 9;
- //(*((DialogPeek)myDialog)->textH)->lineHeight = myFontInfo.ascent + myFontInfo.descent + myFontInfo.leading;
- //(*((DialogPeek)myDialog)->textH)->fontAscent = myFontInfo.ascent;
-
- SetDialogDefaultItem(myDialog, 1);
-
- do {
- ModalDialog(NULL, &myItem);
- } while (myItem != ok);
-
- SetPort(mySavedPort);
- DisposeDialog(myDialog); DebugAssert(MemError() == noErr);
- }
-
-
- //////////
- //
- // ShowWarning
- // Display a warning box.
- //
- //////////
-
- void ShowWarning (Str255 theMessage, OSErr theErr)
- {
- Str255 myErrString;
-
- NumToString(theErr, myErrString);
- ParamText("\pWarning!", theMessage, theErr ? myErrString: NULL, NULL);
- Alert(kAlertError, NULL);
- }
-
-
- // movie-related functions
-
- //////////
- //
- // GetMCFromFrontWindow
- // Get the movie controller associated with the front window.
- //
- //////////
-
- MovieController GetMCFromFrontWindow (void)
- {
- MovieController myMC = NULL;
- WindowRef myWindow = NULL;
- WindowObject myWindowObject = NULL;
-
- myWindow = FrontWindow();
- if (myWindow == NULL)
- return(NULL);
-
- if (!IsAppWindow(myWindow))
- return(NULL);
-
- myWindowObject = (WindowObject)GetWRefCon(myWindow);
- if (myWindowObject == NULL)
- return(NULL);
-
- HLockHi((Handle)myWindowObject);
-
- // make sure this is a window object
- if (!IsWindowObjectOurs(myWindowObject))
- return(NULL);
-
- myMC = (**myWindowObject).fController;
- HUnlock((Handle)myWindowObject);
-
- return(myMC);
- }
-
-
- //////////
- //
- // GetAppDataFromFrontWindow
- // Get the application-specific data associated with the front window.
- //
- //////////
-
- Handle GetAppDataFromFrontWindow (void)
- {
- return(GetAppDataFromWindow(FrontWindow()));
- }
-
-
- //////////
- //
- // GetAppDataFromWindow
- // Get the application-specific data associated with the specified window.
- //
- //////////
-
- Handle GetAppDataFromWindow (WindowRef theWindow)
- {
- WindowObject myWindowObject = NULL;
-
- if (theWindow == NULL)
- return(NULL);
-
- if (!IsAppWindow(theWindow))
- return(NULL);
-
- myWindowObject = (WindowObject)GetWRefCon(theWindow);
- if (myWindowObject == NULL)
- return(NULL);
- else
- return(GetAppDataFromWindowObject(myWindowObject));
- }
-
-
- //////////
- //
- // GetAppDataFromWindowObject
- // Get the application-specific data associated with the specific window object.
- //
- //////////
-
- Handle GetAppDataFromWindowObject (WindowObject theWindowObject)
- {
- Handle myAppData = NULL;
-
- if (theWindowObject == NULL)
- return(myAppData);
-
- // make sure this is a window object belonging to our application
- if (!IsWindowObjectOurs(theWindowObject))
- return(myAppData);
-
- // get the app data handle from the window object
- myAppData = (**theWindowObject).fAppData;
-
- return(myAppData);
- }
-
-
- //////////
- //
- // IsWindowObjectOurs
- // Does the specified window object belong to our application?
- //
- //////////
-
- Boolean IsWindowObjectOurs (WindowObject theObject)
- {
- OSType myType = NULL;
-
- myType = (**theObject).fObjectType;
- if (myType == kMovieControllerObject)
- return(true);
- else
- return(false);
- }
-
-
- //////////
- //
- // DoCreateNewMovie
- // Create a new movie; returns true if successful.
- //
- //////////
-
- Boolean DoCreateNewMovie (void)
- {
- Movie myMovie = NULL;
-
- myMovie = NewMovie(newMovieActive); DebugAssert(myMovie != NULL);
- if (myMovie == NULL)
- return(false);
-
- if (!DoCreateMovieWindow(myMovie))
- return(false);
- else
- return(true);
- }
-
-
- //////////
- //
- // DoCreateMovieWindow
- // Create a new movie window; returns true if successful.
- //
- //////////
-
- Boolean DoCreateMovieWindow (Movie theMovie)
- {
- Rect myRect = gDefaultWinRect;
- WindowRef myWindow = NULL;
- MovieController myMC = NULL;
- WindowObject myWindowObject = NULL;
- GrafPtr mySavedPort;
- short myRefNum;
- short myResID;
- FSSpec myFileFSSpec;
-
- myFileFSSpec.vRefNum = 0;
-
- GetPort(&mySavedPort);
- myWindow = CreateMovieWindow(&myRect, gWindowTitle);
- SetPort((GrafPtr) myWindow);
-
- if (myWindow == NULL)
- return(false);
-
- myWindowObject = CreateWindowObject(myWindow);
- if (myWindowObject == NULL)
- return(false);
-
- // if we don't get a movie, call the internal QTUGetMovie that will get us one.
- if (theMovie == NULL) {
- theMovie = QTUGetMovie(&myFileFSSpec, &myRefNum, &myResID);
- if (theMovie == NULL) { // user selected cancel or otherwise something bad happened.
- DisposeWindow(myWindow); // RTM: added these two lines, to prevent crashing when cancel selected
- SetPort(mySavedPort); // RTM
- return(false);
- }
-
- // add the FSSpec, refnum and resid values to the window object (we need these when we save the movie).
- (**myWindowObject).fFileFSSpec = myFileFSSpec;
- (**myWindowObject).fFileRefNum = myRefNum;
- (**myWindowObject).fFileResID = myResID;
- (**myWindowObject).fMovie = theMovie;
-
- // get movie title and set this to the window title.
- SetWTitle(myWindow, myFileFSSpec.name);
- }
-
- SetMovieGWorld(theMovie, (CGrafPtr)myWindow, 0); // make sure the movie uses the window GWorld in all situations
- myMC = SetupMovieWindowWithController(theMovie, myWindow);
-
- // do any application-specific window object initialization
- InitApplicationWindowObject(myWindowObject);
-
- ShowWindow(myWindow);
- SelectWindow(myWindow); // make it front-most, since it's just been created
- InvalRect(&((GrafPtr)myWindow)->portRect);
-
- MCEnableEditing(myMC, true); // enable the default movie controller editing
-
- SetPort(mySavedPort);
- return(true);
- }
-
-
- //////////
- //
- // SetupMovieWindowWithController
- // Configure the movie controller.
- //
- //////////
-
- MovieController SetupMovieWindowWithController (Movie theMovie, WindowRef theWindow)
- {
- MovieController myMC;
- Rect myRect;
- GrafPtr mySavedPort;
- WindowObject myWindowObject;
- short myMovieWidth;
- short myMovieHeight;
-
- DebugAssert(theMovie != NULL);
- DebugAssert(theWindow != NULL);
-
- myWindowObject = (WindowObject)GetWRefCon(theWindow); // get our window specific data
- if (!IsWindowObjectOurs(myWindowObject))
- return(NULL); // quick sanity test of the window created
- GetPort(&mySavedPort);
- SetPort((GrafPtr)theWindow);
-
- // resize the movie bounding rect
- GetMovieBox(theMovie, &myRect);
- SetMovieBox(theMovie, &myRect);
-
- // create the movie controller.
- myMC = NewMovieController(theMovie, &myRect, gMCFlags);
- if (myMC == NULL)
- return(NULL);
- MCGetControllerBoundsRect(myMC, &myRect);
-
- // add grow box for the movie controller and also an action filter that resizes the controllers
- MCDoAction(myMC, mcActionSetGrowBoxBounds, &gLimitRect);
-
- // install an action filter that resizes the controllers
- // and does any application-specific mc action processing
- MCSetActionFilterWithRefCon(myMC, NewMCActionFilterWithRefConProc(ApplicationMCActionFilterProc), (long)theWindow);
-
- // see if the bounding rects are sane
- myMovieWidth = myRect.right - myRect.left;
- myMovieHeight = myRect.bottom - myRect.top;
-
- myRect.top = myRect.left = 0;
- myRect.right = myMovieWidth;
- myRect.bottom = myMovieHeight;
-
- // resize the window
- SizeWindow(theWindow, myMovieWidth, myMovieHeight, true);
- MoveWindow(theWindow, kDefaultX, kDefaultY, false);
-
- SetPort(mySavedPort);
-
- // add any additional controller functionality
- AddControllerFunctionality(myMC);
-
- // save important stuff into the window object
- {
- Rect myRect;
- OSErr myErr;
-
- (**myWindowObject).fController = myMC;
- myErr = MCGetControllerBoundsRect(myMC, &myRect); DebugAssert(myErr == noErr);
- (**myWindowObject).fOriginalSize = myRect;
- }
-
- return(myMC);
- }
-
-
- //////////
- //
- // DoUpdateMovieFile
- // Update the file (if any) attached to the movie.
- //
- //////////
-
- Boolean DoUpdateMovieFile (WindowRef theWindow)
- {
- Movie myMovie = NULL;
- WindowObject myWindowObject = NULL;
- MovieController myMC = NULL;
- OSErr myErr;
-
- if ((theWindow == NULL) || !IsAppWindow(theWindow))
- return(false);
-
- myWindowObject = (WindowObject)GetWRefCon(theWindow); DebugAssert(myWindowObject != NULL);
- myMC = (**myWindowObject).fController; DebugAssert(myMC != NULL);
-
- if (!(IsWindowObjectOurs(myWindowObject)) && (myMC == NULL))
- return(false);
-
- myMovie = MCGetMovie(myMC); DebugAssert(myMovie != NULL);
- if (myMovie == NULL)
- return(false);
-
- if ( (**myWindowObject).fFileRefNum == -1) { // brand new movie, so no file attached to it.
- if (QTUSaveMovie(myMovie) != noErr)
- return(false);
- } else { // we have an existing file; just update the movie resource
- // open the movie resource file, update the resource, and then close it again!
- myErr = OpenMovieFile(& (**myWindowObject).fFileFSSpec, & (**myWindowObject).fFileRefNum, fsRdWrPerm);
- DebugAssert(myErr == noErr);
- if (myErr != noErr)
- return(false);
-
- myErr = UpdateMovieResource(myMovie, (**myWindowObject).fFileRefNum, (**myWindowObject).fFileResID, NULL);
- DebugAssert(myErr == noErr);
-
- CloseMovieFile((**myWindowObject).fFileRefNum);
- }
-
- if (myErr == noErr)
- return(true);
- else
- return(false);
- }
-
-
- //////////
- //
- // DoDestroyMovieWindow
- // Close the specified movie window.
- //
- //////////
-
- void DoDestroyMovieWindow (WindowRef theWindow)
- {
- Movie myMovie;
- MovieController myMC;
- WindowObject myWindowObject;
-
- DebugAssert(theWindow != NULL);
-
- if (theWindow == NULL)
- return;
-
- myWindowObject =(WindowObject)GetWRefCon(theWindow);
- MoveHHi((Handle)myWindowObject);
- HLock((Handle)myWindowObject);
-
- if (IsWindowObjectOurs(myWindowObject)) {
-
- // do any application-specific window clean-up
- RemoveApplicationWindowObject(myWindowObject);
-
- myMC = (**myWindowObject).fController;
- myMovie = MCGetMovie(myMC);
-
- if (myMovie != NULL)
- DisposeMovie(myMovie); DebugAssert(MemError() == noErr);
-
- if (myMC != NULL)
- DisposeMovieController(myMC); DebugAssert(MemError() == noErr);
-
- if ((**myWindowObject).fFileRefNum != -1)
- CloseMovieFile((**myWindowObject).fFileRefNum);
-
- (**myWindowObject).fObjectType = NULL;
- (**myWindowObject).fController = NULL;
- (**myWindowObject).fFileResID = NULL;
- (**myWindowObject).fFileRefNum = NULL;
-
- DisposeHandle((Handle)myWindowObject); DebugAssert(MemError() == noErr);
- DisposeWindow(theWindow); DebugAssert(MemError() == noErr);
-
- CompactMem(0xFFFFFFFF); // we might as well compact the mem here for getting better performance later.
- }
- }
-
-
- //////////
- //
- // DoActivateWindow
- // Activate the specified window.
- //
- //////////
-
- void DoActivateWindow (WindowRef theWindow, Boolean isBecomingActive)
- {
- WindowObject myWindowObject = NULL;
- MovieController myMC = NULL;
- GrafPtr mySavedPort = NULL;
-
- GetPort(&mySavedPort);
- SetPort((GrafPtr)theWindow);
-
- myWindowObject = (WindowObject)GetWRefCon(theWindow);
- if (myWindowObject != NULL) {
- myMC = (**myWindowObject).fController;
- if ((IsWindowObjectOurs(myWindowObject)) && (myMC != NULL)) {
- MCActivate(myMC, theWindow, isBecomingActive);
- }
- }
-
- SetPort(mySavedPort);
- }
-
-
-
-